﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MySql.Data.MySqlClient;

/// <summary>
/// Summary description for KeyFigure
/// </summary>
public class KeyFigure
{
	private const string STORED_PROCEDURE = "KeyFigure_Get";
	DatabaseManager db;
	MySqlDataReader reader;

	public string Id { get; set; }
	public int Year { get; set; }
	public double GrossMarginRatio { get; set; }
	public double OperatingMargin { get; set; }
	public double ROI { get; set; }
	public double ReturnOnEquity { get; set; }
	public double EquityRatio { get; set; }
	public double DegreeOfliquidity { get; set; }

	public KeyFigure()
	{
		db = new DatabaseManager();
	}

	public void Load(string id, int year)
	{
		db.AddParameter("@id", id);
		db.AddParameter("@year", year);
		using (reader = db.ExecuteStoredProcedure(STORED_PROCEDURE))
		{
			while (reader.Read())
			{
				Id = reader.GetString("id");
				Year = Convert.ToInt32(reader.GetString("year"));
				GrossMarginRatio = Convert.ToDouble(reader.GetString("gross_margin_ratio"));
				OperatingMargin = Convert.ToDouble(reader.GetString("operation_margin"));
				ROI = Convert.ToDouble(reader.GetString("roi").ToString());
				ReturnOnEquity = Convert.ToDouble(reader.GetString("return_on_equity"));
				EquityRatio = Convert.ToDouble(reader.GetString("equity_ratio"));
				DegreeOfliquidity = Convert.ToDouble(reader.GetString("degree_of_liquidity"));
			}
		}
	}
}